package com.google.sydym6.logic.jlayer;

import javazoom.jl.decoder.Obuffer;

public class PcmObuffer extends Obuffer {
	
	private short[] 		buffer;
	private int[] 		bufferp;
	private int 			channels;
	
	public PcmObuffer(int number_of_channels, int freq) {
		buffer = new short[2 * 44100 * 2 * 7];
		bufferp = new int[MAXCHANNELS];
		channels = number_of_channels;
		
		for (int i = 0; i < number_of_channels; ++i) 
			bufferp[i] = (short)i;
	}

	public void append(int channel, short value) {
		buffer[bufferp[channel]] = value;
		//System.out.println(bufferp[channel] + ": " + buffer[bufferp[channel]]);
	    bufferp[channel] += channels;
	}

	@Override
	public void clear_buffer() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void set_stop_flag() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void write_buffer(int arg0) {
		//System.out.println(bufferp[0] + ": " + buffer[bufferp[0]]);
		// TODO Auto-generated method stub
		
	}
	
	public short[] getBuffer() {
		return buffer;
	}
	
	public int getLength() {
		int r;
		if (channels < 2) r = bufferp[0];
		else r = Math.max(bufferp[0], bufferp[1]);
		return r;
	}
	

}
